package effect
{
	import flash.display.DisplayObjectContainer;
	import flash.display.Loader;
	import flash.display.MovieClip;
	import flash.events.*;
	import flash.geom.*;
	import flash.net.*;
	import flash.system.*;
	import flash.text.*;
	
	import kim.effect.ui.Text;
	
	[SWF(backgroundColor="#000000", frameRate="30", width="600", height="600")]
	public class ScaleMain extends MovieClip
	{
		private var array:Array;
		private var list:MovieClip;
		private var myphoto:Scale;//图片滚动对象
		private var contain:MovieClip=new MovieClip();
		private var loader:Loader;
		public function ScaleMain()
		{
			init();
		}
		private function init():void
		{
			myphoto=new Scale(stage);//初始化对象
			myphoto.max=1.4;//设置最大缩放比例
			myphoto.ratio=0.0025;//设置自定义比例
			myphoto.distance=10;//设置图片间的距离
			createObj();
			addEventListener(Event.ENTER_FRAME,Run);
			addChild(contain);
		}
		//创建物体
		private function createObj():void
		{
			array = new Array();
			list = new MovieClip();
			list.y=60;
			list.x=200;
			list.name = "list";
			addChild(list);
			
			for (var i:uint=0; i<10; i++)
			{
				var myclass:Object= Text;		
				var bit:MovieClip= new myclass() as MovieClip;
				bit.title.text="Menu"+i;
				bit.ID=i;
				bit.mouseChildren = false;
				bit.buttonMode = true;
				bit.x =20;
				bit.y =bit.height/2+i*(bit.height+10);
				array.push(bit);
				list.addChild(bit);
				bit.addEventListener(MouseEvent.MOUSE_DOWN,listdown);
			}
			stage.addEventListener(MouseEvent.MOUSE_MOVE,listmove);
		}
		private function Run(event:Event):void
		{
			//memory.text=String(System.totalMemory/1024)+"/kb";//内存监控
		}
		private function listmove(e:MouseEvent):void
		{
			if (list.hitTestPoint(mouseX,mouseY))
			{
				myphoto.ZoomPhotoY(array);//以y轴为例
			}
			else
			{
				System.gc();
				myphoto.RestPosition(array,"y");
			}
		}
		private function listdown(event:MouseEvent):void
		{
			trace(event.currentTarget);
			removeAllChildren(contain);//删除容器中对象
			load("./image/" + event.currentTarget.ID + ".png");
		}
		//加载外部图片
		private function load(path:String):void
		{
			loader=new Loader();
			loader.contentLoaderInfo.addEventListener(Event.COMPLETE,onComplete);
			loader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR,onError);
			loader.load(new URLRequest(path));
		}
		private function onComplete(event:Event):void
		{
			loader.removeEventListener(Event.COMPLETE,onComplete);
			contain.addChild(event.currentTarget.content);
			contain.alpha=0;
			contain.x=150;
			contain.y=100;
			
		}
		private function onError(event:Event):void
		{
			throw new Error("路径错误");			
		}
		
		private function removeAllChildren(container:DisplayObjectContainer):void
		{
			while (container.numChildren>0)
			{
				container.removeChildAt(0);
			}
			
		}
	}
}